package com.crm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.crm.base.ResponseResult;
import com.crm.domain.entity.Notice;
import com.crm.service.NoticeService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Xanny YuJia
 */
@RestController
@RequestMapping("/system/notice")
@RequiredArgsConstructor
@Api(tags = "公告管理")
public class NoticeController {

    private final NoticeService noticeService;


    /**
     * 分页的简单完成
     * @param status
     * @return
     */
    @GetMapping("/pagelist/{status}")
    public ResponseResult getNoticeId(@PathVariable("status") Integer status) {
        Page<Notice> page = noticeService.lambdaQuery().eq(Notice::getStatus,status).page(new Page<>(1, 100));
        return ResponseResult.success()
                .put("rows", page.getRecords())
                .put("total", page.getTotal());
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("{ids}")
        public ResponseResult deleteNotice(@PathVariable List<Long> ids) {
            ids.forEach(id -> {
                noticeService.lambdaUpdate().eq(Notice::getNoticeId,id).remove();
            });
            return ResponseResult.success();
        }

    @GetMapping("/list/{id}")
    public ResponseResult getNotice(@PathVariable Long id) {
        return ResponseResult.success();
    }
}